﻿@using Utils;
@model WebUI.Models.EditJobViewModel
@{
    ViewBag.Title = "Edit a Job - JuicyBasket";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>Edit a Job</h1>
<div class="mainSection">
    <div class="clear"></div>
    <div class="mainCol jp">
        @if (Model.Job == null || Model.Job.JobID <= 0)
        { 
            <div class="null-message">
	            <h2>The job listing can not be found. Go back to your <a href="/company/joblist">job list</a></h2>
            </div>
        }
        else if (!Model.Job.Editable)
        { 
            <div class="null-message">
	            <h2>Sorry, you can not edit this job information any more since the listing has been published for more than 3 days. We allow user to edit the job listing which has been published in only 3 days </h2>
            </div>
        }
        else
        {
            <div style="font-size:16px;">This job is still editable in @Model.Job.EditableHours hours. Please note that the changes will go live automatically after you click "Save".</div>
            <div class="tabsbottom"></div>
            using (Html.BeginForm("EditJob", "Co", FormMethod.Post, new { ID = "EditJobForm" }))
            {
                @Html.HiddenFor(m => m.Job.JobID)
                <div class="clear"></div>
                <div class="fl left">Job Title<span>&nbsp;*</span></div>
                <div class="fl right">
                    @Html.TextBoxFor(m => m.Job.Title)
                    @Html.ValidationMessageFor(m => m.Job.Title)
                </div>
                <div class="minispacer"></div>
            
                <div class="clear"></div>
                <div class="fl left">Job Type<span>&nbsp;*</span></div>
                <div class="fl right">
                    @Html.DropDownListFor(m => m.Job.JobTypeID, Model.JobTypeList)
                </div>
                <div class="minispacer"></div>
            
                <div class="clear"></div>
                <div class="fl left">Experience<span>&nbsp;*</span></div>
                <div class="fl right">
                    @Html.DropDownListFor(m => m.Job.JobExpID, Model.JobExpList)
                </div>
                <div class="minispacer"></div>
            
                <div class="clear"></div>
                <div class="fl left">Location<span>&nbsp;*</span></div>
                <div class="fl right">
                    @Html.TextBoxFor(m => m.Job.Location)
                    @Html.ValidationMessageFor(m => m.Job.Location)
                </div>
            
                <div class="clear"></div>
                <div class="fl left left-tip">&nbsp;</div>
                <div class="fl right right-tip">e.g. "Los Angeles, CA", "London, UK", "Anywhere"</div>
                <div class="smallspacer"></div>
            
                <div class="fl left">&nbsp;</div>
                <div class="fl right">
                    @Html.CheckBoxFor(m => m.Job.RelocationOffered) Relocation assistance offered for this position
                    <div class="minispacer"></div>
                    @Html.CheckBoxFor(m => m.Job.AllowTelecommute) Work can be done from anywhere (i.e. telecommuting)
                </div>
                <div class="minispacer"></div>
            
                <div class="clear"></div>
                <div class="fl left">Compensation</div>
                <div class="fl right">
                    @Html.TextBoxFor(m => m.Job.Compensation)
                    @Html.ValidationMessageFor(m => m.Job.Compensation)
                </div>
                <div class="clear"></div>
                <div class="fl left left-tip">&nbsp;</div>
                <div class="fl right right-tip">e.g. Salary, bonus, stock, etc"</div>
                <div class="smallspacer"></div>
            
                <div class="clear"></div>
                <div class="fl left">Description<span>&nbsp;*</span></div>
                <div class="fl right">
                    @Html.TextAreaFor(m => m.Job.Description, new { ID = "desTextArea" })
                    @Html.ValidationMessageFor(m => m.Job.Description)
                </div>
                <div class="spacer"></div>
            
                <div class="clear"></div>
                <div class="fl left">Job Keywords</div>
                <div class="fl right">
                     @Html.TextBoxFor(m => m.Job.JobKeywords)
                     @Html.ValidationMessageFor(m => m.Job.JobKeywords)
                </div>
                <div class="clear"></div>
                <div class="fl left left-tip">&nbsp;</div>
                <div class="fl right right-tip">Key technologies or roles (up to 5, separated by commas), e.g. "web design, html, css, php" </div>
                <div class="spacer"></div>
            
                <div class="fl left">Job Perks</div>
                <div class="fl right">
                    @Html.TextAreaFor(m => m.Job.Perk)
                    @Html.ValidationMessageFor(m => m.Job.Perk)
                </div>
                <div class="clear"></div>
                <div class="fl left left-tip">&nbsp;</div>
                <div class="fl right right-tip">
                    <span id="perk_totalchars"></span>&nbsp;(Html tag is <em>not</em> allowed)
                    <div class="minispacer"></div>
                    <div>
                        Sell your position! If you're willing to relocate, mention it here. If you've got great benefits, bonuses, paid trips to conferences, free food, discounts, pet-friendly etc., talk it up.
                    </div>
                </div>
                <div class="spacer"></div>
            
                <div class="tabsbottom"></div>
            
                <div class="clear"></div>
                <div class="fl left">How to apply<span>&nbsp;*</span></div>
                <div class="fl right">
                    @Html.RadioButtonFor(m => m.Job.ApplyViaEmail, true) Apply by this email address: <br/>
                    @Html.TextBoxFor(m => m.Job.ApplyEmail)
                    @Html.ValidationMessageFor(m => m.Job.ApplyEmail)
                    <div class="minispacer"></div>
                    <div>- OR -</div>
                    <div class="minispacer"></div>
                    @Html.RadioButtonFor(m => m.Job.ApplyViaEmail, false) Apply via url below: <br />
                    @Html.TextBoxFor(m => m.Job.ApplyUrl)
                    @Html.ValidationMessageFor(m => m.Job.ApplyUrl)
                </div>
                <div class="spacer"></div>
            
                <div class="fl left">Instructions</div>
                <div class="fl right">
                    @Html.CheckBoxFor(m => m.Job.OnlinePortfolioRequired) Online portfolio required
                    <div class="minispacer"></div>
                    @Html.CheckBoxFor(m => m.Job.OnlinePDFResumeRequired) Online text/pdf resume required
                </div>
                <div class="minispacer"></div>
            
                <div class="tabsbottom"></div>
                <div class="fr">
                    <a class="gray-submit" href="/company/joblist">Cancel</a>&nbsp;&nbsp;
                    <input type="submit" id="submitJob" name="submitJob" value="Save" class="blue-submit" />
                </div>
            
            }
        }
    </div>
    <div class="sideCol">
        <div class="spacer"></div>
    </div>
    <div class="clear"></div>
</div>

@section FooterContent
{
    <script type="text/javascript" src="@Url.StaticFile("~/content/jquery.form.js")"></script>
    <script type="text/javascript" src="@Url.StaticFile("~/content/tinyMCE/tiny_mce.js", true)"></script>
    <script type="text/javascript">
        $(function () {
            initTinyMCE("desTextArea", 480, 600);

            textAreaCharsRemaining("Job_Perk", "perk_totalchars", 500);

            toggleApplyMethod();
            $("input[name='Job.ApplyViaEmail']").change(function () {
                toggleApplyMethod();
            });

            //ajax submit payment form
            $("#EditJobForm").ajaxForm({
                beforeSerialize: function (f, o) {
                    //for ajax form, and for tinyMCE, beforeSerialize, we need save textArea 
                    tinyMCE.get("desTextArea").save();
                },
                beforeSubmit: function (a, f, o) {
                },
                dataType: 'json',
                success: ProcessForm,
                error: function (request, status, errorThrown) {     // error during save, display error
                    //alert(request.responseText);
                    return false;
                }
            });
        });

        function toggleApplyMethod() {
            var value = $("input[name='Job.ApplyViaEmail']:checked").val().toLowerCase();
            if (value == "true") {
                $("input[name='Job.ApplyUrl']").val("");
                $("input[name='Job.ApplyUrl']").attr("disabled", "disabled");
                $("input[name='Job.ApplyEmail']").removeAttr("disabled");
            }
            else {
                $("input[name='Job.ApplyEmail']").val("");
                $("input[name='Job.ApplyEmail']").attr("disabled", "disabled");
                $("input[name='Job.ApplyUrl']").removeAttr("disabled");
            }
        }

        function ProcessForm(data) {
            JsonResultHandler.Success(data);
            
        }
    </script>
}